package com.idealighter.game.web.personctl.controller.dto;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;

import com.idealighter.game.core.common.Game;
import com.idealighter.game.games.fruitslot.struct.FruitslotDifficulty;
import com.idealighter.game.games.jcby.struct.JcbyDifficulty;
import com.idealighter.game.games.lkby.struct.LkbyDifficulty;
import com.idealighter.game.games.shuihu.struct.ShuiHuDifficulty;
import com.idealighter.game.player.service.bo.PlayerBo;
import com.idealighter.game.player.struct.Player;
import com.idealighter.game.prizepool.struct.control.BlackjackControl;
import com.idealighter.game.prizepool.struct.control.FishDifficulty;
import com.idealighter.game.prizepool.struct.control.FruitslotControl;
import com.idealighter.game.prizepool.struct.control.JcbyControl;
import com.idealighter.game.prizepool.struct.control.LkbyControl;
import com.idealighter.game.prizepool.struct.control.SharkControl;
import com.idealighter.game.prizepool.struct.control.ShuiHuControl;
import com.idealighter.game.prizepool.struct.control.SiRenNiuNiuControl;
import com.idealighter.game.prizepool.struct.control.ZjhControl;
import com.idealighter.game.prizepool.struct.player.PlayerPrizePool;
import com.idealighter.game.web.common.controller.dto.FruitSlotControlDto;
import com.idealighter.game.web.common.controller.dto.JcbyControlDto;
import com.idealighter.game.web.common.controller.dto.LkbyControlDto;
import com.idealighter.game.web.common.controller.dto.ShuiHuControlDto;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import lombok.Data;

@Data
public class PlayerCtrlDetailInfoDto {
  private PlayerCtrlBasicInfoDto playerInfo;
  private CtlDetailsDto games;

  public PlayerCtrlDetailInfoDto(PlayerBo domain) {
    this.playerInfo = new PlayerCtrlBasicInfoDto(domain);
    this.games = new CtlDetailsDto(domain.prizePools());
  }

  public PlayerCtrlDetailInfoDto(Player player) {
    this.playerInfo = new PlayerCtrlBasicInfoDto(player);
    this.games = new CtlDetailsDto(player.prizePools());
  }

  @Data
  public static class CtlDetailsDto {
    private ShuiHuDto shuihu;
    private LabaDto laba;
    private FqzsDto fqzs;
    private LkbyDto lkby;
    private JcbyDto jcby;
    private SiRenNiuNiuDto srnn;
    private ZjhDto zjh;
    private BlackJackDto blackJack;

    /**
     * 构造函数 .
     * 
     * @param prizePool 所有奖池.
     */
    public CtlDetailsDto(Map<Integer, PlayerPrizePool> prizePool) {
      if (prizePool != null) {
        this.shuihu = new ShuiHuDto(prizePool.get(Game.SHUI_HU_ZHUAN.getType()));
        this.laba = new LabaDto(prizePool.get(Game.FRUIT_SLOT.getType()));
        this.fqzs = new FqzsDto(prizePool.get(Game.FQZS.getType()));
        this.lkby = new LkbyDto(prizePool.get(Game.LKBY.getType()));
        this.jcby = new JcbyDto(prizePool.get(Game.JCBY.getType()));
        this.srnn = new SiRenNiuNiuDto(prizePool.get(Game.SIREN_NIUNIU.getType()));
        this.zjh = new ZjhDto(prizePool.get(Game.ZJH.getType()));
        this.blackJack = new BlackJackDto(prizePool.get(Game.BLACK_JACK.getType()));
      }
    }

    @Data
    public static class ShuiHuDto {
      private Integer gameId;
      private ShuiHuContrlInfoDto control;
      private List<ShuiHuControlDto> difficultList;

      /**
       * 构造函数 .
       * 
       * @param prizePool 奖池.
       */
      public ShuiHuDto(PlayerPrizePool prizePool) {
        this.gameId = Game.SHUI_HU_ZHUAN.getType();
        if (prizePool != null) {
          this.control = new ShuiHuContrlInfoDto(prizePool);
        }

        difficultList = new ArrayList<ShuiHuControlDto>();
        for (ShuiHuDifficulty item : ShuiHuDifficulty.values()) {
          difficultList.add(new ShuiHuControlDto(item.getDifficulty(), item.getName()));
        }
      }

      @Data
      public static class ShuiHuContrlInfoDto {
        private Long prizePools;
        private Integer difficulty;

        /**
         * 构造函数 .
         * 
         * @param prizePool 奖池.
         */
        public ShuiHuContrlInfoDto(PlayerPrizePool prizePool) {
          this.prizePools = prizePool.getPrize().get();
          ShuiHuControl shuiHuControl =
              JSON.parseObject(prizePool.getControl(), new TypeReference<ShuiHuControl>() {});
          this.difficulty = shuiHuControl.getDifficulty();
        }
      }
    }

    @Data
    public static class LabaDto {
      private Integer gameId;
      private LaBaContrlInfoDto control;
      private List<FruitSlotControlDto> difficultList;

      /**
       * 构造函数 .
       * 
       * @param prizePool 奖池.
       */
      public LabaDto(PlayerPrizePool prizePool) {
        this.gameId = Game.FRUIT_SLOT.getType();
        if (prizePool != null) {
          this.control = new LaBaContrlInfoDto(prizePool);
        }

        difficultList = new ArrayList<FruitSlotControlDto>();
        for (FruitslotDifficulty item : FruitslotDifficulty.values()) {
          difficultList.add(new FruitSlotControlDto(item.getDifficulty(), item.getName()));
        }
      }

      @Data
      public static class LaBaContrlInfoDto {
        private Long prizePools;
        private Integer difficulty;

        /**
         * 构造函数 .
         * 
         * @param prizePool 奖池.
         */
        public LaBaContrlInfoDto(PlayerPrizePool prizePool) {
          this.prizePools = prizePool.getPrize().get();
          FruitslotControl fruitslotControl =
              JSON.parseObject(prizePool.getControl(), new TypeReference<FruitslotControl>() {});
          this.difficulty = fruitslotControl.getDifficulty();
        }
      }
    }

    @Data
    public static class FqzsDto {
      private Integer gameId;
      private FqzsContrlInfoDto control;

      /**
       * 构造函数 .
       * 
       * @param prizePool 奖池.
       */
      public FqzsDto(PlayerPrizePool prizePool) {
        this.gameId = Game.FQZS.getType();
        if (prizePool != null) {
          this.control = new FqzsContrlInfoDto(prizePool);
        }
      }

      @Data
      public static class FqzsContrlInfoDto {
        private Long prizePools;
        // 系统赢得概率
        private int winRatio;
        // 系统输得概率
        private int loseRatio;

        /**
         * 构造函数 .
         * 
         * @param prizePool 奖池.
         */
        public FqzsContrlInfoDto(PlayerPrizePool prizePool) {
          this.prizePools = prizePool.getPrize().get();
          SharkControl sharkControl =
              JSON.parseObject(prizePool.getControl(), new TypeReference<SharkControl>() {});
          this.winRatio = sharkControl.getWinRatio();
          this.loseRatio = sharkControl.getLoseRatio();
        }
      }
    }

    @Data
    public static class LkbyDto {
      private Integer gameId;
      private LkbyContrlInfoDto control;
      private List<LkbyControlDto> difficultList;

      /**
       * 构造函数 .
       * 
       * @param prizePool 奖池.
       */
      public LkbyDto(PlayerPrizePool prizePool) {
        this.gameId = Game.LKBY.getType();
        if (prizePool != null) {
          this.control = new LkbyContrlInfoDto(prizePool);
        }
        difficultList = new ArrayList<LkbyControlDto>();
        for (LkbyDifficulty item : LkbyDifficulty.values()) {
          difficultList.add(new LkbyControlDto(item.getDifficulty(), item.getName()));
        }
      }

      @Data
      public static class LkbyContrlInfoDto {
        private Long prizePools;
        private List<FishDifficulty> difficultys;

        /**
         * 构造函数 .
         * 
         * @param prizePool 奖池.
         */
        public LkbyContrlInfoDto(PlayerPrizePool prizePool) {
          this.prizePools = prizePool.getPrize().get();
          LkbyControl lkbyControl =
              JSON.parseObject(prizePool.getControl(), new TypeReference<LkbyControl>() {});
          lkbyControl.getDifficultys();
          this.difficultys = lkbyControl.getDifficultys();
        }
      }
    }

    @Data
    public static class JcbyDto {
      private Integer gameId;
      private JcbyContrlInfoDto control;
      private List<JcbyControlDto> difficultList;

      /**
       * 构造函数 .
       * 
       * @param prizePool 奖池.
       */
      public JcbyDto(PlayerPrizePool prizePool) {
        this.gameId = Game.JCBY.getType();
        if (prizePool != null) {
          this.control = new JcbyContrlInfoDto(prizePool);
        }
        difficultList = new ArrayList<JcbyControlDto>();
        for (JcbyDifficulty item : JcbyDifficulty.values()) {
          difficultList.add(new JcbyControlDto(item.getDifficulty(), item.getName()));
        }
      }

      @Data
      public static class JcbyContrlInfoDto {
        private Long prizePools;
        private List<FishDifficulty> difficultys;

        /**
         * 构造函数 .
         * 
         * @param prizePool 奖池.
         */
        public JcbyContrlInfoDto(PlayerPrizePool prizePool) {
          this.prizePools = prizePool.getPrize().get();
          JcbyControl jcbyControl =
              JSON.parseObject(prizePool.getControl(), new TypeReference<JcbyControl>() {});
          this.difficultys = jcbyControl.getDifficultys();
        }
      }
    }

    @Data
    public static class SiRenNiuNiuDto {
      private Integer gameId;
      private SiRenNiuNiuContrlInfoDto control;

      /**
       * 构造函数 .
       * 
       * @param prizePool 奖池.
       */
      public SiRenNiuNiuDto(PlayerPrizePool prizePool) {
        this.gameId = Game.SIREN_NIUNIU.getType();
        if (prizePool != null) {
          this.control = new SiRenNiuNiuContrlInfoDto(prizePool);
        }
      }

      @Data
      public static class SiRenNiuNiuContrlInfoDto {
        private Long prizePools;
        // 系统赢得概率
        private int winRatio;
        // 系统输得概率
        private int loseRatio;

        /**
         * 构造函数 .
         * 
         * @param prizePool 奖池.
         */
        public SiRenNiuNiuContrlInfoDto(PlayerPrizePool prizePool) {
          this.prizePools = prizePool.getPrize().get();
          SiRenNiuNiuControl srnnControl =
              JSON.parseObject(prizePool.getControl(), new TypeReference<SiRenNiuNiuControl>() {});
          this.winRatio = srnnControl.getWinRatio();
          this.loseRatio = srnnControl.getLoseRatio();
        }
      }
    }

    @Data
    public static class ZjhDto {
      private Integer gameId;
      private ZjhContrlInfoDto control;

      /**
       * 构造函数.
       * 
       * @param prizePool 奖池.
       */
      public ZjhDto(PlayerPrizePool prizePool) {
        this.gameId = Game.ZJH.getType();
        if (prizePool != null) {
          this.control = new ZjhContrlInfoDto(prizePool);
        }
      }

      @Data
      public static class ZjhContrlInfoDto {
        private Long prizePools;
        // 系统赢得概率
        private int winRatio;
        // 系统输得概率
        private int loseRatio;

        /**
         * 构造函数.
         * 
         * @param prizePool 奖池.
         */
        public ZjhContrlInfoDto(PlayerPrizePool prizePool) {
          this.prizePools = prizePool.getPrize().get();
          ZjhControl zjhControl =
              JSON.parseObject(prizePool.getControl(), new TypeReference<ZjhControl>() {});
          this.winRatio = zjhControl.getWinRatio();
          this.loseRatio = zjhControl.getLoseRatio();
        }
      }
    }

    @Data
    public static class BlackJackDto {
      private Integer gameId;
      private BlackJackInfoDto control;

      /**
       * 构造函数.
       * 
       * @param prizePool 奖池.
       */
      public BlackJackDto(PlayerPrizePool prizePool) {
        this.gameId = Game.BLACK_JACK.getType();
        if (prizePool != null) {
          this.control = new BlackJackInfoDto(prizePool);
        }
      }

      @Data
      public static class BlackJackInfoDto {
        private Long prizePools;
        // 系统赢得概率
        private int winRatio;
        // 系统输得概率
        private int loseRatio;

        /**
         * 构造函数.
         * 
         * @param prizePool 奖池.
         */
        public BlackJackInfoDto(PlayerPrizePool prizePool) {
          this.prizePools = prizePool.getPrize().get();
          BlackjackControl zjhControl =
              JSON.parseObject(prizePool.getControl(), new TypeReference<BlackjackControl>() {});
          this.winRatio = zjhControl.getWinRatio();
          this.loseRatio = zjhControl.getLoseRatio();
        }
      }
    }
  }
}
